package com.winterwar.service.impl;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.winterwar.base.Event;
import com.winterwar.dao.EventDAO;
import com.winterwar.service.EventManager;

public class EventManagerImpl implements EventManager {

	public Event get(String eventID) {
		Event event = dao.get(Integer.valueOf(eventID));
		if(event == null){
			log.warn("Event with ID " + eventID + " does not exist in database.");
		}
		return event;
	}

	public List getAll() {
		return dao.getAll();
	}

	public void remove(String eventID) {
		dao.remove(Integer.valueOf(eventID));
	}

	public Event save(Event event) {
		dao.save(event);
		return event;
	}

	public void setDAO(EventDAO dao) {
		this.dao = dao;
	}

	public List getByConID(String conID, String status) {
		return dao.getByConID(Integer.valueOf(conID), status);
	}
	
	public Event getByTableSlot(Integer slotID, Integer tableID) {
		List events = dao.getByTableSlot(slotID, tableID);
		if(events.size() > 0) return (Event) events.get(0);
		else return null;
	}

	private EventDAO dao;
	private static Log log = LogFactory.getLog(EventManager.class);
}
